package com.flavors.wan.main.ui;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.plat.sdk.common.LazyFragment;
import com.plat.sdk.okgo.callbck.XmResource;

import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * create an instance of this fragment.
 */
public abstract class BaseFragment extends LazyFragment {
    private Unbinder mUnBinder;

    /**
     * 初始化控件
     */
    protected abstract void initView();

    public BaseFragment() {
    }


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Log.d("ydong", this.getClass().getSimpleName() + "\tonViewCreated");
        if (mUnBinder == null && getRootView() != null) {
            mUnBinder = ButterKnife.bind(this, getRootView());
        }
        initView();
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d("ydong", this.getClass().getSimpleName() + "\tonDestroyView");
        if (mUnBinder != null) {
            mUnBinder.unbind();
            mUnBinder = null;
        }
    }

    /**
     * 在BaseActivity基类中增加这个目的是减少回调页面过多的显示造成的页面不清晰
     *
     * @param <T>
     */
    public class SimpleOnHandleCallBack<T> implements XmResource.OnHandleCallback<T> {
        @Override
        public void onLoading() {
        }

        @Override
        public void onSuccess(T data) {

        }

        @Override
        public void onFailure(String message) {
        }

        @Override
        public void onError(int code, String message) {
        }

        @Override
        public void onCompleted() {
        }
    }


}
